<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>让一个div水平垂直居中</title>
    <style>
      /* .parent {
        width: 400px;
        height: 400px;
        position: relative;
        border: 1px solid #ccc;
      }
      .child {
        width: 100px;
        height: 100px;
        position: absolute;
        left: 50%;
        top: 50%;
        background-color: red;
        transform: translate(-50%, -50%);
        margin-left: -50px;
        margin-top: -50px;
      } */
      .parent {
        width: 400px;
        height: 400px;
        border: 1px solid #ccc;
        display: flex;
        /* justify-content: center;
        align-items: center; */
      }
      .child {
        margin: auto;
        width: 100px;
        height: 100px;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div class="parent">
      <div class="child"></div>
    </div>
  </body>
</html>
